package com.jwl.idc.paser;

import com.google.gson.Gson;
import com.jwl.idc.actionbean.BaseBean;
import com.jwl.idc.actionbean.Devices;
import com.jwl.idc.actionbean.UserBean;


/**
 * Created by liangfan on 2016/1/4.
 * descript: 将String类型解析为java对象
 */
public class DataPaser {
    public static final int DEVICE_LIST_PASER = 0x001;
    public static final int GET_SMS_PASER = 0x002;
    public static final int REGISTER_USER = 0x003;
    public static final int LOGIN_USER = 0x004;

    public static BaseBean dataPaser(String data, int key){
        BaseBean bb = new BaseBean();
        Gson gson = new Gson();
        switch (key){
            case DEVICE_LIST_PASER:
                Devices devices = gson.fromJson(data, Devices.class);
                return devices;
            case GET_SMS_PASER:
            case REGISTER_USER:
                bb = gson.fromJson(data,BaseBean.class);
                return bb;
            case LOGIN_USER:
                UserBean user = gson.fromJson(data, UserBean.class);
                return user;
        }
        return bb;
    }
}
